package cn.car91.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.car91.R;
import cn.car91.view.MarqueeTextView;

public class OilListAdapter extends BaseAdapter {
    private LayoutInflater layoutInflater;
    private Context context;
    private List<Oil> data;

    public List<Oil> getData() {
        return data;
    }

    public void setData(List<Oil> data) {
        this.data = data;
    }

    public void addData(List<Oil> data) {
        this.data.addAll(data);
    }

    public OilListAdapter(Context context) {
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
        this.data = new ArrayList<Oil>();
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return data.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return data.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    public class Oil {
        public String name;
        public String address;
        public String oil0;
        public String oil90;
        public String oil93;
        public String oil97;
    }

    public Oil instanceOil() {
        return new Oil();
    }

    public class OilItem {
        public MarqueeTextView name;
        public MarqueeTextView address;
        public TextView oil0;
        public TextView oil90;
        public TextView oil93;
        public TextView oil97;
    }

    @Override
    public View getView(int arg0, View arg1, ViewGroup arg2) {
        // TODO Auto-generated method stub
        OilItem oilItem = null;
        if (arg1 == null) {
            oilItem = new OilItem();

            arg1 = layoutInflater.inflate(R.layout.view_oil, null);
            oilItem.name = (MarqueeTextView) arg1.findViewById(R.id.oil_basic_name);
            oilItem.address = (MarqueeTextView) arg1.findViewById(R.id.oil_basic_address);
            oilItem.oil0 = (TextView) arg1.findViewById(R.id.oil_0);
            oilItem.oil90 = (TextView) arg1.findViewById(R.id.oil_90);
            oilItem.oil93 = (TextView) arg1.findViewById(R.id.oil_93);
            oilItem.oil97 = (TextView) arg1.findViewById(R.id.oil_97);
            arg1.setTag(oilItem);
        } else {
            oilItem = (OilItem) arg1.getTag();
        }
        Oil oil = data.get(arg0);
        oilItem.name.setText(oil.name);
        oilItem.address.setText(oil.address);
        oilItem.oil0.setText(oil.oil0);
        oilItem.oil90.setText(oil.oil90);
        oilItem.oil93.setText(oil.oil93);
        oilItem.oil97.setText(oil.oil97);
        return arg1;
    }

}
